$(document).ready(function () {
    singleArticle();


});

var getParam = function(name){
    var search = document.location.search;
    var pattern = new RegExp("[?&]"+name+"\=([^&]+)", "g");
    var matcher = pattern.exec(search);
    var items = null;
    if(null != matcher){
        try{
            items = decodeURIComponent(decodeURIComponent(matcher[1]));
        }catch(e){
            try{
                items = decodeURIComponent(matcher[1]);
            }catch(e){
                items = matcher[1];
            }
        }
    }
    return items;
};

function singleArticle(){
    $.ajax({
        url:"http://123.207.241.214/api/getSingleOne",
        type:"POST",
        async:true,
        data:{id:getParam("id")},
        timeout:5000,
        dataType:'json',
        success:function (data) {
            if (data['code'] == 1){
                console.log(data['data']['article_title']);
                $("#articleId").text(data['data']['article_title'])
                $("#article_time").text(data['data']['article_create_at'])
                $("#article_author").text(data['data']['article_author'])
                $("#article_content").html(data['data']['article_content'])
                $("#singleImg").attr("src",'https://picsum.photos/750/421/?random')

            }else {
                alert("获取失败，请重试");
            }
        },
        error:function () {
            console.log("失败");
        }
    })
}

